package com.yanqu.road.server.cmd.marriage;

import com.yanqu.road.entity.marriage.MarriageInfo;
import com.yanqu.road.logic.pb.MarriagePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.marriage.CrossMarriageProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.marriage.CrossUnionMarriageMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_AGREE_UNION_MARRIAGE_DEAL, desc = "同意跨服商会联姻处理")
public class CrossUnionMarriageAgreeDealCmd extends CrossCommand {
    private long userId;
    private MarriageInfo marriageInfo;
    private String partnerChildUid;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossMarriageProto.CrossMarriageAgreeCrossDealReqMsg reqMsg = CrossMarriageProto.CrossMarriageAgreeCrossDealReqMsg.parseFrom(packet.getBytes());
        marriageInfo = MarriagePb.parseMarriageInfo(reqMsg.getApplyData());
        partnerChildUid = reqMsg.getPartnerChildUid();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ret = CrossUnionMarriageMgr.agreeMarriage(userId, marriageInfo, partnerChildUid);
    }

    @Override
    public void sendData() {
        if(0 != ret) {
            CrossMarriageProto.CrossMarriageApplyAgreeRespMsg.Builder respMsg = CrossMarriageProto.CrossMarriageApplyAgreeRespMsg.newBuilder();
            respMsg.setRet(ret);
            YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.U_CROSS_UNION_MARRIAGE_APPLY_AGREE, respMsg);
            MessageHelper.sendPacket(serverId, userId, pbMsg);
        }
    }
}
